﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using GPSTracker.Helper;
using System.Text;

namespace GPSTracker.Views.DAL
{
    public class CustomerDAL
    {
        public DataTable FillCustomerMasterGrid(string strCustomerID)
        {
            var sb = new StringBuilder();
            var dt = new DataTable();

            if (strCustomerID == string.Empty)
            {
                var strSQL = "SELECT * FROM dbo.VW_Customer";
                var da = new SqlDataAdapter(strSQL, CommonFx.GetSqlCon());
                da.Fill(dt);
            }
            else
            {
                sb.Append("SELECT * FROM dbo.VW_Customer WHERE CustomerID = '" + strCustomerID + "' ");
                var da = new SqlDataAdapter(sb.ToString(), CommonFx.GetSqlCon());
                da.Fill(dt);
            }
            return dt;
        }

        public DataTable FillArea()
        {
            var sb = new StringBuilder();
            var dt = new DataTable();

            var strSQL = "SELECT * FROM dbo.VW_GetArea ";
            var da = new SqlDataAdapter(strSQL, CommonFx.GetSqlCon());
            da.Fill(dt);
            return dt;
        }

        public void DeleteCustomerMaster(string strCustomerID)
        {
            var sb = new StringBuilder();
            sb.Append("DELETE FROM dbo.M_Customer WHERE CustomerID = '" + strCustomerID + "' ");

            var cmd = new SqlCommand(sb.ToString(), CommonFx.GetSqlCon());
            cmd.ExecuteNonQuery();
        }
    }
}
